/**
 * @see https://leetcode-cn.com/problems/longest-common-prefix/
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function(strs) {
  let max = [];

  function getIndex(p, code) {
    let same = true;
    for (let i = 1; i < strs.length; i++) {
      const element = strs[i];
      if(element[p] != code) {
        same = false;
        break;
      }
    }
    return same;
  }
  for (let i = 0; i < strs[0].length; i++) {
    let same = getIndex(i, strs[0][i]);
    if(same) {
      max.push(strs[0][i]);
    } else {
      break;
    }
  }
  console.log(max.join(''))
  return max.join('')
};

longestCommonPrefix(["flower","flow","flight"]);
longestCommonPrefix(["cir","car"]);
// longestCommonPrefix(["dog","racecar","car"]);